package com.lxf.cloudorder.controller;

import com.alibaba.fastjson.JSONObject;
import com.lxf.cloudfeign.client.productClient.ProductClient;
import com.lxf.cloudorder.annotate.OrderRateLimit;
import com.lxf.cloudorder.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author 罗兴发
 * @data 2024/12/23 16:42
 * @description：
 */
@RestController
@CrossOrigin  //跨域
@RequestMapping("/v1")
@Slf4j
public class OrderController {
    @Resource
    ProductClient productClient;
    @Resource
    OrderService orderService;

    /**
     *
     * 添加订单
     *
     * @return
     */
    @OrderRateLimit(value = 1,timeout = 3)
    @PostMapping("/addOrder")
    public String addOrder(@RequestBody JSONObject json,HttpServletRequest request){
        log.info("进入订单模块");
        return orderService.addOrder(json,request);
    }

    /**
     *
     * 根据用户ID获取获取订单列表
     *
     * @return
     */
    @OrderRateLimit(value = 5,timeout = 3)
    @PostMapping("/getOrderByUserId")
    public String getOrderByUserId(@RequestBody JSONObject json){
        return orderService.getOrderByUserId(json);
    }

    /**
     * 打印订单
     *
     * @return
     */
    @OrderRateLimit(value = 5,timeout = 3)
    @PostMapping("/printOrderById")
    public String printOrderById(@RequestBody JSONObject json,HttpServletRequest request){
        return orderService.printOrderById(json,request);
    }

    /**
     *
     * 获取产品列表
     *
     * @return
     */
    @OrderRateLimit(value = 5,timeout = 3)
    @PostMapping("/getOrderByGoodName")
    public String getOrderByGoodName(@RequestBody JSONObject json,HttpServletRequest request){
        return orderService.getOrderByGoodName(json,request);
    }
}
